package com.wsl.myexception.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author ：wangshuliang
 * @date ：Created in 2019/6/5 8:58
 * @description：异常切面类
 * @modified By：
 */
@Slf4j
@Component
@Aspect
public class ExceptionAspect {
    @Pointcut("execution(public * com.wsl.myexception.service.ExceptionService.*(..))")
    public void er(){}

    /**
     *  throwing  定义参数  https://www.cnblogs.com/ssslinppp/p/4633595.html
     *  声明ex时指定的类型会限制目标方法,必须抛出指定类型的异常
     *  此处将ex的类型声明为Throwable，意味着对目标的方法抛出的异常不加限制
     * @param joinPoint
     * @param ex
     */
    @AfterThrowing(pointcut = "er()",throwing = "ex")
    public void throwExce(JoinPoint joinPoint,Throwable ex){
        log.info("捕获到了异常"+ex);
        log.info("对象是什么"+ joinPoint.getThis());
        log.info(joinPoint.getSignature().getDeclaringTypeName());
        log.info(joinPoint.getSignature().getDeclaringType().toString());
    }

}
